package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcThicknessDAO;
import com.virtium.vpc.hibernate.model.VpcThickness;


public class VpcThicknessManager {
	private static ArrayList<VpcThickness> arrVpcThickness = null;

	public static ArrayList<VpcThickness> getAll() {
		try {
			if (arrVpcThickness != null && arrVpcThickness.size() > 0)
				return arrVpcThickness;
			VpcThicknessDAO VpcThicknessDAO = DAOFactory.getInstance().getThicknessDAO();
			arrVpcThickness = new ArrayList<VpcThickness>();
			arrVpcThickness.addAll(VpcThicknessDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcThickness;
	}
	
	public static String getTextByID(int id){
		//if(id == null)return;
		getAll();
		Iterator<VpcThickness> iterObject = arrVpcThickness.listIterator();
		while(iterObject.hasNext()){
			VpcThickness object = iterObject.next();
			if(object.getId().equals(id))return object.getText2();
			
		}
		return "";
	}
	
	public static void AddNew(String text,String text2){
		try{
			VpcThickness object = new VpcThickness();
			object.setText(text);
			object.setText2(text2);
			VpcThicknessDAO ObjectDAO = DAOFactory.getInstance().getThicknessDAO();
			ObjectDAO.save(object);
			arrVpcThickness = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcThicknessDAO ObjectDAO = DAOFactory.getInstance().getThicknessDAO();
			VpcThickness object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcThickness = null;
		}catch(Exception ex){
			
		}
	}
}
